cmake_minimum_required(VERSION 3.18)
project(rtbus)

set(ECAT_ENABLE 1)
set(CCAN_ENABLE 1)

if (ECAT_ENABLE)
    message(STATUS "Ethercat enabled")
    add_definitions(-DECAT_ENABLE)
    aux_source_directory(ethercat ECAT_SRCS)
    set(ECAT_LIB soem)
    set(ECAT_INCLUDE_DIR ${JKZUC_ROOT_DIR}/3rd/SOEM ${JKZUC_ROOT_DIR}/3rd/SOEM/soem)
endif()

if (CCAN_ENABLE)
    message(STATUS "CCAN enabled")
    add_definitions(-DCCAN_ENABLE)
    set(CCAN_LIB_DIR ${JKZUC_ROOT_DIR}/3rd/controlcan)
    set(CCAN_SRCS can/ccan.cc)
    set(CCAN_LIB controlcan)
endif()

link_directories(
    ${CCAN_LIB_DIR}
    )

add_library(${PROJECT_NAME}
rtbus.cc
can/jkcan.cc
can/canitf.cc
can/libsocketcan.c
can/scan.cc
${CCAN_SRCS}
${ECAT_SRCS}
)

target_link_libraries(${PROJECT_NAME}
PRIVATE hwdrv
PRIVATE ${ECAT_LIB}
PUBLIC ${CCAN_LIB} 
PUBLIC pthread 
)
target_include_directories(${PROJECT_NAME}
PRIVATE ${ECAT_INCLUDE_DIR}
PRIVATE ${JKZUC_ROOT_DIR}/3rd/SOEM
PRIVATE ./
)

add_subdirectory(test)